#ifndef __LISTLOOPMODEL_H__
#define __LISTLOOPMODEL_H__

#include "PlayModelBase.h"
#include "MusicListManager.h"

namespace SPlayer
{
    ref class ListLoopModel : public PlayModelBase
    {
    public:
        ListLoopModel(MusicListManager ^muscListManager)
            : _musicListManager(muscListManager), _currentList()
        {}
        virtual PlayModelBase::NextMusicInfo ^next()
        = PlayModelBase::next
        {
            if (!_currentList)
                return nullptr;
            auto items = _musicListManager->items;
            MusicListManager::MusicList ^list = items[_currentList];

            if (list->Count == 0)
                return nullptr;

            auto index = list->IndexOf(_currentMusicInfo);
            auto nextIndex = (index  + 1) % list->Count;

            auto newMusicInfo = list[nextIndex];
            return gcnew PlayModelBase::NextMusicInfo(_currentList, newMusicInfo);
        }
        virtual void onMusicPlay(System::String ^currentList, Music::MusicInfo ^_currentMusicInfo)
        = PlayModelBase::onMusicPlay
        {
            this->_currentList = currentList;
            this->_currentMusicInfo = _currentMusicInfo;
        }
    private:
        System::String ^_currentList;
        Music::MusicInfo ^_currentMusicInfo;
        MusicListManager ^_musicListManager;
    };
}

#endif // __LISTLOOPMODEL_H__